from Setting import Setting
from DataManager import DataManager
from SimpleDialogs import DialogLogin

def login():
    retl = []
    d = DialogLogin(retl)
    ret = d.ShowModal()
    d.Destroy()
    if ret == 0:
        Setting.set('username', retl[1])
        if retl[0] == 1:
            Setting.set('save_password', 1)
            Setting.set('password', retl[2])
        else:
            #clear all saved
            Setting.set('save_password', 0)
            Setting.set('password', '')
        Setting.save()
        
        if retl[0] != 1:
            #this complement the else case above
            #NOTE: though we cleaned setting in save, we actually need them
            #at runtime
            Setting.set('password', retl[2])
    return ret    
